import { createRouter, createWebHashHistory } from 'vue-router'


const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    name: 'home',
    path: '/home',
    component:()=>import('../components/Home/Home.vue')
  },
  {
    name: 'cart',
    path: '/cart',
    component:()=>import('../components/Cart/Cart.vue')
  },
  {
    name: 'user',
    path: '/user',
    component:()=>import('../components/User/User.vue')
  },
  {
    name: 'order',
    path: '/order',
    component:()=>import('../components/Order/Order.vue')
  },
  {
    name: 'login',
    path: '/login',
    component:()=>import('../components/Login/Login.vue')
  },
  {
    name:'register',
    path: '/register',
    component: () => import('../components/Register/Register.vue')
  },
  {
    name: 'mallDetail',
    path: '/mallDetail',
    component:()=>import('../components/Home/MallDetail.vue')
  }
]
const router = createRouter({
  history: createWebHashHistory(),
  routes
  
})
router.beforeEach((to, from, next) => { 
  if (to.name == 'login' || to.name == 'register') {
    next()
  } else { 
    if (localStorage.getItem('cookie')=='done') {
      next()
    } else { 
      next({name:"login"})
    }
  }
})

export default router